package com.jason.game.online.home.adapter

import android.content.Context
import android.view.View
import com.jason.game.online.utils.ChangeButtonStyleUtils.changeButtonStyle
import com.cby.library.data.model.GameInfoBean
import com.cby.library.widget.adapter.SimpleBaseAdapter
import com.jason.game.online.R
import android.view.ViewGroup
import android.widget.ImageView
import com.jason.game.online.widget.GameTitleItem
import com.jason.game.online.widget.GameCategoryItem
import android.widget.TextView
import com.cby.library.common.ext.load
import com.cby.library.widget.TintButton
import com.jason.game.online.utils.ChangeButtonStyleUtils

/**
 * 描述信息
 *
 * @author 徐智伟
 * @create 2018/11/28
 */
class GameListItem1Adapter(
    context: Context?,
    data: MutableList<GameInfoBean>
) : SimpleBaseAdapter<GameInfoBean>(context, data as List<GameInfoBean>) {
    override fun getItemResource(): Int {
        return R.layout.item_home_grid_1
    }

    override fun getItemView(
        position: Int, convertView: View, parent: ViewGroup,
        holder: ViewHolder
    ): View {
        val gameTitleItem: GameTitleItem = holder.findView(R.id.tv_game_item_name)
        val categoryItem: GameCategoryItem = holder.findView(R.id.tv_game_item_category)
        val introduceTextView: TextView = holder.findView(R.id.tv_game_item_introduce)
        val playIv: ImageView = holder.findView(R.id.iv_play)
        val iconImageView: ImageView = holder.findView(R.id.iv_game_item_icon)
        val item = data[position]!!
        gameTitleItem.setData(item.title, item.gift)
        introduceTextView.text = item.summary
        iconImageView.load(item.icon, R.drawable.loading_bixue)

        val playButton: TintButton = holder.findView<TintButton>(R.id.btn_game_item_play)
        changeButtonStyle(playButton, item.test)
        if (item.test != null && item.test != ChangeButtonStyleUtils.API_TEST_MODEL_END) {
            playButton.isClickable = true
            //H5ViewClickUtils.bindGamePlayButtonClick(playButton, item, "");
        } else {
            playButton.isClickable = false
        }
        return convertView
    }
}